package com.bwie.service.impl;

import com.bwie.common.domain.Business;
import com.bwie.common.domain.Dict;
import com.bwie.common.domain.Follow;
import com.bwie.common.domain.Keep;
import com.bwie.common.exceptions.BizExceptions;
import com.bwie.mapper.BusinessMapper;
import com.bwie.oss.OssUtil;
import com.bwie.service.BusinessService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.List;

/**
 * @className: BusinessServiceImpl
 * @Description: TODO
 * @version: v1.８.0
 * @author: GONGWENXUE
 * @date: 2025/10/10 11:20
 */
@Service
public class BusinessServiceImpl implements BusinessService {
    @Autowired
    BusinessMapper businessMapper;
    @Autowired
    RedisTemplate redisTemplate;
    @Autowired
    OssUtil ossUtil;
    @Autowired
    RabbitTemplate rabbitTemplate;
    @Override
    public List<Business> bussList(Business business) {
        return businessMapper.bussList(business);
    }

    @Override
    public Integer addBuss(Keep keep) {
        //10、完成商机的添加操作
        //11、添加商机的时候，需要从缓存当中获取字典数据(商机类型、来源等)
        //12、添加商机的时候，提醒方式多选，并支持发送邮件
        Business business = keep.getBusiness();
        Follow follow = keep.getFollow();
         businessMapper.addBuss(business);
        businessMapper.addFollow(follow);
        rabbitTemplate.convertAndSend("aaa","发送成功");
        return 1;
    }



    @Override
    public String upload(MultipartFile[] multipartFiles) {
        if(multipartFiles.length<=0){
            throw new BizExceptions("请选择照片");
        }
        StringBuffer stringBuffer = new StringBuffer();
        Arrays.stream(multipartFiles).forEach(file->{
            String s = ossUtil.uploadMultipartFile(file);
            stringBuffer.append(s+";");
        });
        return stringBuffer.toString();
    }

    @Override
    public List<Business> getMyBusinessesWithRemind(Long businessId) {
        return businessMapper.getMyBusinessesWithRemind(businessId);
    }
}